package com.hisense.ovcloud.asop.config;

public class Constants {
    public static class ClickhouseConfigs {
        public final static String DRIVER = "clickhouse";
        public final static String DEFAULT_DATABASE = "default";
        public final static String DEFAULT_USER = "default";
        public final static String DEFAULT_PASSWORD = "";
        public final static String DEFAULT_PROTOCOL = "http";
    }

    public final static int TOP_N_SIZE = 1;
    public static class PairLogType {
        public final static String ADD_DEVICE_TRACK = "add_device_track";
        public final static String CDC_TYPE = "ciam_track";
    }
    public static class SqlTemplates {
        public final static String PAIR_LOG_GROUP_BY_PAIRID_PREFIX = """
                select * from (
                select log_id, os, app_version, timezone, os_version, type, app_name, user_id, model, app_build_ersion, udid, event, brand, pairid,
                app_ersion, deviceid, wifiid, create_time, result_code, result_info, pairtype, properties, partitiondate
                from applog.all_pair_applog
                where
               """;
        public final static String PAIR_LOG_GROUP_BY_PAIRID_MEDIUM = """
                isNotNull(pairid) and type=:type and partitiondate >= :beginTime and partitiondate <= :endTime )
               """;
        public final static String PAIR_LOG_GROUP_BY_PAIRID_SUFFIX = """
                order by log_id desc
                limit 1 by pairid
               """;

        public final static String FIND_PAIR_LOG_BY_PAIRID = """
                select log_id, os, app_version, timezone, os_version, type, app_name, user_id, model, app_build_ersion, udid, event, brand, pairid,
                app_ersion, deviceid, wifiid, create_time, result_code, result_info, pairtype, properties, partitiondate
                from applog.all_pair_applog
                where partitiondate >= :beginTime and partitiondate <= :endTime and isNotNull(pairid) and pairid=:pairid and type=:type and isNotNull(wifiid) 
                order by log_id
               """;

        public final static String SELECT_BY_TYPE_AND_TIME = """
                select log_id, os, app_version, timezone, os_version, type, app_name, user_id, model, app_build_ersion, udid, event, brand, pairid,
                app_ersion, deviceid, wifiid, create_time, result_code, result_info, pairtype, properties, partitiondate
                from applog.all_pair_applog
                where multiMatchAny(properties, ['__MAIL_MD5__']) and type=:type and partitiondate >= :beginTime and partitiondate <= :endTime
                order by create_time desc
               """;

        public final static String WIFI_STATUS_SEARCH = """
                select wifi_id, wifi_version, owner_server, status_time, partitiondate, country, net_id, wifi_status
                from applog.all_wifi_status
                where wifi_id in (__WIFI_IDS__) and partitiondate >= :beginTime and partitiondate <= :endTime
                order by status_time desc
               """;

        public final static String QUERY_AC_JULINK_LOG = """
                select logtime, message, pod_name
                from k8sapplog.all_oversea_smarthome_acjulink
                where logtime >= '__BEGIN_TIME__'
                and logtime <= '__END_TIME__'
                and multiMatchAny(message, ['__WIFIID__'])
                and multiMatchAny(filename, ['WARN'])
                order by logtime asc
                limit __LIMIT__
                """;

        public final static String QUERY_AC_JULINK_ANALYSIS_LOG = """
                select wifi_id AS wifiId, logtime, channel_no as channelNo, channel_type as channelType, 
                duration, error, raw_logtime as rawLogtime, pod_name as podName
                from service_log.all_service_log_analysis_julink
                where logtime >= '__BEGIN_TIME__'
                and logtime <= '__END_TIME__'
                and wifi_id = '__WIFIID__'
                order by logtime asc
                limit __LIMIT__
                """;



        public final static String QUERY_SERVICE_METRIC_BIZ_LOG = """
                select service, path,
                sum(request_total) as requestTotal, 
                sum(request_failure_total) as requestFailureTotal,
                round(sum(request_failure_total)/sum(request_total), 2) as requestFailureRate,
                round(sum(request_total)/ :queryTimeSeconds) as requestQps,
                min(min_duration_ms) as minDurationMS,
                max(max_duration_ms) as maxDurationMS, 
                avg(avg_duration_ms) as avgDurationMS, 
                max(tp90_duration_ms) as tp90DurationMS,
                max(tp95_duration_ms) as tp95DurationMS, 
                max(tp99_duration_ms) as tp99DurationMS
                from service_log.all_service_log_metric_biz
                where logtime > :beginTime and logtime < :endTime
                __CONDITION__
                group by service, path
                __ORDER__
                """;
    }

    public static class DS {
        public final static String WGDB = "wgdb";
        public final static String BIGDATA = "bigdata";

    }

    public final static long VERY_EARLY = 1050000000000L;
    public final static long VERY_LATER = 4127072000000L;
    public final static String WIFI_ID_CANNOT_BE_FOUND = "WIFI_ID_CANNOT_BE_FOUND";

    public final static int SUCCESS = 0;
    public final static int FAILED = 1;
    public final static int INVALID_TOKEN = 401;
    public final static class ERRORS {
        public final static String BAD_TOKEN = "invalid token";
    }
}
